import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.ActionListener;

/**
 * ****************************************************************************
 * $Author: Yegor Chemisov $
 * $Revision: 2.2 $
 * ****************************************************************************
 */

public class MainMenu
{
    public JMenuBar createMenuBar(ActionListener actionListiner)
    {
        JMenuBar menuBar;
        JMenu menu, gridSize, playMode;
        JMenuItem menuItem;

        //Create the menu bar.
        menuBar = new JMenuBar();

        //Build the first menu.
        menu = new JMenu(MAPConsts.RES.getString(GlobalRes.MENU_GAME));
        menu.setMnemonic(KeyEvent.VK_G);
        menuBar.add(menu);

        //a group of JMenuItems
        menuItem = new JMenuItem(MAPConsts.RES.getString(GlobalRes.MENU_NEW), KeyEvent.VK_N);
        menuItem.setActionCommand(MAPActions.NEW);
        menuItem.addActionListener(actionListiner);
        menu.add(menuItem);

        menu.addSeparator();
        /*
        // --- Menu Play Mode ---
        playMode = new JMenu(MAPConsts.RES.getString(GlobalRes.MENU_PLAY_MODE));

        menuItem = new JMenuItem(MAPConsts.RES.getString(GlobalRes.MENU_MODE_TIMING), KeyEvent.VK_T);
        menuItem.setActionCommand(MAPActions.TIMING);
        menuItem.addActionListener(actionListiner);
        playMode.add(menuItem);

        menuItem = new JMenuItem(MAPConsts.RES.getString(GlobalRes.MENU_MODE_HUMAN), KeyEvent.VK_P);
        menuItem.setActionCommand(MAPActions.PLAYER);
        menuItem.addActionListener(actionListiner);
        playMode.add(menuItem);

        menuItem = new JMenuItem(MAPConsts.RES.getString(GlobalRes.MENU_MODE_COMPUTER), KeyEvent.VK_C);
        menuItem.setActionCommand(MAPActions.COMPUTER);
        menuItem.addActionListener(actionListiner);
        playMode.add(menuItem);

        menu.add(playMode);
        */

        gridSize = new JMenu(MAPConsts.RES.getString(GlobalRes.MENU_GRID_SIZE));
        for (int i = 0; i < MAPConsts.GRID_SIZE.length; i++)
        {
            menuItem = new JMenuItem(MAPConsts.GRID_SIZE[i]);
            menuItem.setActionCommand(MAPActions.GRID_SIZE + i);
            menuItem.addActionListener(actionListiner);
            //rbItem.setSelected();
            gridSize.add(menuItem);
        }

        menuItem = new JMenuItem(MAPConsts.RES.getString(GlobalRes.MENU_CUSTOM), KeyEvent.VK_C);
        menuItem.setActionCommand(MAPActions.CUSTOM);
        menuItem.addActionListener(actionListiner);
        gridSize.add(menuItem);
        menu.add(gridSize);

        menuItem = new JMenuItem(MAPConsts.RES.getString(GlobalRes.MENU_BEST_TIMES), KeyEvent.VK_B);
        menuItem.setActionCommand(MAPActions.BEST_TIMES);
        menuItem.addActionListener(actionListiner);
        menu.add(menuItem);

        menuItem = new JMenuItem(MAPConsts.RES.getString(GlobalRes.MENU_ABOUT), KeyEvent.VK_A);
        menuItem.setActionCommand(MAPActions.ABOUT);
        menuItem.addActionListener(actionListiner);
        menu.add(menuItem);

        menu.addSeparator();

        menuItem = new JMenuItem(MAPConsts.RES.getString(GlobalRes.MENU_EXIT), KeyEvent.VK_X);
        menuItem.getAccessibleContext().setAccessibleDescription(
                "Close Game");
        menuItem.setActionCommand(MAPActions.EXIT);
        menuItem.addActionListener(actionListiner);
        menu.add(menuItem);

        return menuBar;
    }
}
